package com.xk857.school.mapper;

import com.xk857.entities.Comment;
import com.xk857.entities.TourismComment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 星空小屋-组团旅行评论表 Mapper 接口
 * </p>
 *
 * @author CV大魔王
 * @since 2021-05-02
 */
public interface TourismCommentMapper extends BaseMapper<TourismComment> {


    /**
     * 根据组团id查询评论信息
     * @param tourismId 组团id
     * @return
     */
    @Select("SELECT * FROM school_tourism_comment WHERE parent_id = -1 AND tourism_id = #{tourismId} ORDER BY create_date DESC")
    @Results({
            @Result(column = "id", property = "children", javaType = List.class, many = @Many(select = "com.xk857.school.mapper.TourismCommentMapper.findChildrenByCommentId")),
            @Result(column = "id", property = "id")
    })
    List<TourismComment> findByTourismId(String tourismId);


    /**
     * 根据评论id查询子评论
     * @param id 评论id
     * @return 所有子评论集合
     */
    @Select("SELECT * FROM school_tourism_comment WHERE parent_id = #{id}")
    @Results({
            @Result(column = "id", property = "children", javaType = List.class, many = @Many(select = "com.xk857.school.mapper.TourismCommentMapper.findChildrenByCommentId")),
            @Result(column = "id", property = "id")
    })
    List<TourismComment> findChildrenByCommentId(@Param("id") String id);
}
